package ge.telasi.tasks.model;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 * @author dimitri
 */
@Entity
@Table(name = "task_attachments")
public class TaskAttachment extends Modifiable implements Serializable {
    private static final long serialVersionUID = -6801846745972751040L;

    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "TASK_ATTACHMENT_SEQ")
	@SequenceGenerator(name = "TASK_ATTACHMENT_SEQ", sequenceName = "TASK_ATTACHMENT_SEQ", allocationSize = 1)
    private Long id;
    @Column(name = "binary_id")
    private long binaryId;
    @Column(name = "name")
    private String name;
    @Column(name = "data_length")
    private int length;
    @ManyToOne
    @JoinColumn(name = "owner_id")
    private User owner;
    @ManyToOne
    @JoinColumn(name = "task_id")
    private Task task;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public long getBinaryId() {
        return binaryId;
    }

    public void setBinaryId(long contentId) {
        this.binaryId = contentId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public Task getTask() {
        return task;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    @Override
    public boolean equals(Object obj) {
        if (id == null) {
            return false;
        }
        if (obj instanceof TaskAttachment) {
            TaskAttachment binaryData = (TaskAttachment) obj;
            return id.equals(binaryData.getId());
        }
        return false;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }
}
